package com.ptu.mapper;

import com.github.pagehelper.Page;
import com.ptu.entity.SeckillOrder;
import com.ptu.vo.SeckillOrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SeckillOrderMapper {
    @Select("select count(*) from seckill_order where user_id=#{userId} and product_id=#{productId}")
    int getByUserIdAndProductId(Long userId, Long productId);

    @Insert("insert into seckill_order(product_id,user_id,name,price,status,created_time,updated_time) values(#{productId},#{userId},#{name},#{price},#{status},NOW(),NOW())")
    void add(SeckillOrder seckillOrder);

    @Update("update seckill_order set status=2,updated_time=NOW() where id=#{id}")
    Void cancleById(Long id);
    
    @Update("update seckill_order set status=6,updated_time=NOW() where id=#{id}")
    Void refund(Long id);



    @Select("select * from seckill_order where id= #{id}")
    SeckillOrder detail(Long id);

    @Update("update seckill_order set status=4,updated_time=NOW() where id= #{id}")
    Void complete(Long id);

    @Select("select * from seckill_order")
    Page<SeckillOrder> list();

    @Update("update seckill_order set status= 3,updated_time=NOW() where id= #{id}")
    void updateStatusById(Long id);

    @Update("update seckill_order set status= 5,updated_time=NOW() where id= #{id}")
    void adminRefund(Long id);

    @Update("update seckill_order set status= #{status},updated_time=NOW() where id= #{id}")
    void updateStatusByIdAndStatus(Long id,Integer status);

    @Select("select * from seckill_order where user_id= #{userId}")
    List<SeckillOrderVO> userGetList(Integer userId);

    @Update("update seckill_order set status= 1,updated_time=NOW() where id= #{id}")
    Void pay(Long id);
}
